<script>

var passGerente = false;
var qtdAtual = 0;
var cod_ped = 0;
var bt_obj;
var vsrc = 130;
var btn_click = false;
var exclude_click = false;

$(function(){
	if(user.caf01_admin == 1)
		$(".excluir-div").show();
});

function excl(cod)
{
	if($(".bt_" + cod).val())
	{
		$(".exc_" + cod).fadeIn("fast");
	}
}

function addMUnDiv(un, bt)
{
	if(!(aux = parseInt(un)))
	{
		aux = 1;
	}

	if(itens_pedido)
	{
		itens_pedido += ",";
	}

	itens_pedido += bt;

	addUnDiv(aux, bt);
}

function getGerente()
{
	if(auxJson.caf01_admin != 0)
	{
		$(".manager").fadeOut("fast");

		passGerente = true;

		resetPassword();

		$(bt_obj).val(qtdAtual);

		if(exclude_click)
		{
			$.post('pedido/deleteqtd', {cod_menu: $("#subgroups").val(), cod: cod_ped, cod_item: auxPedido, un: qtdAtual}, function(req){
				listProd();
			});

			if(qtdAtual == 0)
			{
				$(".bt_" + cod_ped).val("");
				$(".exc_" + cod_ped).fadeOut("fast");
			}
			
			exclude_click = false;

			return;
		}

		/*$.post('pedido/saveqtd', {cod_menu: $("#subgroups").val(), cod: cod_ped, cod_item: auxPedido, un: qtdAtual}, function(req){
			listProd();
		});*/

		return true;
	}
	else
	{
		alert("Senha de Gerente invalida.");

		passGerente = false;

		resetPassword();

		return false;
	}
}

function openUn(cod)
{
	//$(".bt_" + cod).select();
	$(".un_" + cod).slideDown("fast");
	btn_click = true;
	//$(".bt_" + cod).slideDown("fast");
}

function filter(a, obj)
{
	$(".filter a").css("textDecoration", "none");
	$(obj).css("textDecoration", "underline");

	if(a == "*")
	{
		return;
	}
	
	$(".subprod").hide();
	document.getElementById("lisProdDiv").scrollTop = 0;
	$("." + a).fadeIn("fast");

	
}

function deleteReg(cod)
{
	$.post('pedido/deleteqtd', 
		{cod_menu: $("#subgroups").val(), cod: cod, cod_item: auxPedido}, 
		function(req){
			msg({vmsg: 'Item excluido.'});
			listProd();
	});
}

function addUnDiv(un, bt)
{
	var auxQtd = parseInt(un);
	
	if(!un)
	{
		var velm = parseInt($(".bt_" + bt).val());
		auxQtd = velm - 1;

		exclude_click = true;
	}

	$(".bt_" + bt).val(auxQtd).focus().blur();
}

function addQtdProd(cod)
{
		$.post('pedido/saveqtd', {cod_menu: $("#subgroups").val(), cod: cod, cod_item: auxPedido}, function(req){
			listProd(cod);
		});
		
		return true;
}



</script>

<div class="ui-corner-all" style="position: absolute; opacity: 0.8; margin-left: 500px; margin-top: 36px; width: 32px; background: #DFDFDF;">
	<div onclick="moveUp('lisProdDiv');" class="ui-corner-top" style="padding-top: 5px; padding-bottom: 3px; background: #CFCFCF">
		<img src="public/images/actions/up.png" />
	</div>
	<div onclick="moveDown('lisProdDiv');" class="ui-corner-bottom" style="background: #CFCFCF; margin-top: 195px; padding-top: 7px;">
		<img src="public/images/actions/down.png" />
	</div>
</div>

<?php 

if($this->arr_prod)
{
	$arr_prod = $this->arr_prod;
	$menu = $arr_prod[0]["caf03_menu"];
}
else
{
	die("<i>Vazio</i>");
}


echo "<label style='font-weight: bold'>$menu</label>";
echo "<label id='load_subproduct' style='font-weight: bold; display: none;'>&nbsp;<img src='$this->base/public/images/ajax-loader.gif' /></label>";

switch ($menu)
{
	case "Soft Drinks":
?>
	<div style="text-align: center; float: right;" class="filter">
		<i>Filtros:</i>
		<a href="javascript:;" style="color: blue;  padding: 10px; text-decoration: underline;" onclick="javascript:$('.subprod').hide();$('.subprod').fadeIn('fast'); filter('*', this);" >Todos</a>
		|
		<a href="javascript:;" style="color: blue; padding: 10px; text-decoration: none;" onclick="javascript:filter('Lata', this);" >Lata</a>
		|
		<a href="javascript:;" style="color: blue; padding: 10px; text-decoration: none;" onclick="javascript:filter('600ml', this);">600ml</a>
		|
		<a href="javascript:;" style="color: blue; padding: 10px; text-decoration: none;" onclick="javascript:filter('Copo', this);" >Copo</a>
	</div>
<?
	break;
	
	case "Pizza":
?>
	<div style="text-align: center; float: right;" class="filter">
		<i>Filtros:</i>
		<a href="javascript:;" style="color: blue; padding: 10px; text-decoration: underline;" onclick="javascript:$('.subprod').fadeIn('fast'); filter('*', this);" >Todos</a>
		|
		<a href="javascript:;" style="color: blue; padding: 10px; text-decoration: none;" onclick="javascript:filter('Small', this);" >Pequeno</a>
		|
		<a href="javascript:;" style="color: blue; padding: 10px; text-decoration: none;" onclick="javascript:filter('Medium', this);">Medio</a>
		|
		<a href="javascript:;" style="color: blue; padding: 10px; text-decoration: none;" onclick="javascript:filter('Large', this);" >Grande</a>
	</div>
<?
	break;
}

?>

<hr style="margin-top: 8px; margin-bottom: 8px;" />

<div id="lisProdDiv" style="height: 280px; overflow: hidden;">
	<?php 
	
	if(is_array($arr_prod))
	{
		foreach ($arr_prod as $key => $val)
		{
			$color = "";
			
			if($this->edit && $val["caf04_qtd"])
			{
				$color = "border: 1px solid gray;";
			}
			else
			{
				$color = "border: 1px solid gray;";
			}
		?>
			<div class="<?php echo $val["caf05_car"]; ?> subprod" 
			style="float: left; width: 125px; margin: 0px; 
			text-align: center;border-right: 0; border-top: 0;">
				<div style="position: relative;">
					<div class="ui-corner-all button" 
					style="<?php if($lo = $val["caf05_logo"]){echo "background-image: url('$this->base/public/images/logo/$lo'); background-repeat: no-repeat; background-position: 50% 50%;";}; ?> 
					width: 120px; height: 80px; border: 1px solid gray; border-right: 0; border-top: 0;" 
					onclick="addQtdProd(<?php echo $val["caf05_cod"]; ?>);"
					 >
						<div style="margin: 3px; padding-top: 4px;">
							<?php echo "{$val["caf05_prod"]}<br />({$val["caf05_car"]})"; ?>
							<hr style="margin: 3px; border-top: 1px dotted;" />
							$<?php echo Num::money($val["caf05_valor"]); ?>/un
						</div>
						<div style="position: absolute; margin-left: 67px; width: 50px; text-align: right;">
							<font size='1'>cod:<?php echo $val["caf05_cod"]; ?></font>
						</div>
					</div>
				</div>
				<div style="width: 120px;  text-align: center;">
					<input class="bt_<?php echo $val["caf05_cod"]; ?>" onblur="excl(<?php echo $val["caf05_cod"]; ?>); $('.un_<?php echo $val["caf05_cod"]; ?>').slideUp(); addQtdProd('<?php echo $val["caf05_cod"]; ?>', $(this).val(), '<?php echo $val["caf04_qtd"]; ?>', this);" onclick="" type="hidden" value="<?php echo $val["caf04_qtd"]; ?>" style="<?php echo $color; ?> font-size: 18px; padding: 5px 0 5px 0; height: 25px; width: 120px;" />
					<div class="" 
					onclick="deleteReg(<?php echo $val["caf05_cod"]; ?>);" 
					style="padding: 10px 0 10px 0; border: 1px solid gray; margin-top: 2px; width: 120px; 
					border-top: 0; border-right: 0; border-top: 0; display: none;">
						Excluir
					</div>
				</div>
				<!-- 
				<div style="opacity: 0.9; z-index: 999; position: absolute; display: none; text-align: left; font-size: 24px; width: 166px; border: 1px solid #B0ADAD; background-color: white; margin-left: 0px;" class="ui-widget ui-corner-all unit un_<?php echo $val["caf05_cod"]; ?>" >
					<div id="exclDiv_<?php echo $val["caf05_cod"]; ?>" class="ui-corner-top" onclick="addUnDiv(0, '<?php echo $val["caf05_cod"]; ?>');" style="padding: 5px; background-color: #EFEFEF; display: none;">
						<div style="float: left; margin: 0px 3px 0px 0px;">
							<img src="public/images/actions/delete.png" /> 
						</div>
						<div style="margin-top: 2px;">
							Excluir
						</div>
					</div>
					<div onclick="showComentario(<?php echo $val["caf05_cod"]; ?>);" style="border-bottom: 1px solid #B0ADAD; border-top: 1px solid #B0ADAD; padding: 5px;">
						<div style="float: left; margin: 0px 3px 0px 0px;">
							<img src="public/images/actions/msg.png" /> 
						</div>
						<div style="margin-top: 2px;">
							Mensagem
						</div>
					</div>
					<?php 
					$excl_btn = "";
					
					if(!$val["caf04_qtd"])
					{
						$excl_btn = "display: none;";
					}
					
					?>
					<div onclick="keybnumShow({title: '<?php echo $val["caf05_prod"]; ?>', bg: 'true', elm: '<?php echo $val["caf05_cod"]; ?>'});" style=" padding: 5px;">
					<div style="float: left; margin: 0px 3px 0px 0px; border-bottom: 0;">
							<img src="public/images/actions/keynum.png" /> 
						</div>
						<div style="margin-top: 2px;">
							Teclado
						</div>
					</div>
				</div>
				-->
				<!-- 
				<select onclick="addQtdProd('<?php echo $val["caf05_cod"]; ?>', this);" style="font-size: 18px; padding: 5px 0 5px 0; height: 40px; width: 170px;">
					<option value="">Un</option>
					<?php 
					for($i = 1; $i < 15; $i++)
					{
						$select = "";
						
						if($val["caf04_qtd"] == $i)
						{
							$select = 'selected="selected"';
						}
					?>
					<option <?php echo $select; ?> ><?php echo $i; ?></option>				
					<?
					}
					?>
				</select>
				-->
			</div>
		<?php 
		}
		?>
	<?php 
	}
	else 
	{
	?>
	<i>Nenhum produto</i>
	<?php 
	}
	?>

</div>